package embeddedTomcat;
//http://affy.blogspot.com/2006/10/embedded-tomcat-5517-eclipse-project.html
import org.apache.catalina.startup.Bootstrap;

	import java.io.File;
	import java.io.IOException;

	import org.mortbay.jetty.Connector;
	import org.mortbay.jetty.Handler;
	import org.mortbay.jetty.NCSARequestLog;
	import org.mortbay.jetty.Server;
	import org.mortbay.jetty.handler.ContextHandlerCollection;
	import org.mortbay.jetty.handler.DefaultHandler;
	import org.mortbay.jetty.handler.HandlerCollection;
	import org.mortbay.jetty.handler.RequestLogHandler;
	import org.mortbay.jetty.nio.SelectChannelConnector;
	import org.mortbay.jetty.security.SslSocketConnector;
	import org.mortbay.jetty.webapp.WebAppContext;

	public class EmbeddedJetty {
	   public static void main(String[] args) throws Exception
	   {
		   Server server = new Server();
			  
		   Connector connector = new SelectChannelConnector();
		   connector.setPort(8080);
		   server.addConnector(connector);

		   SslSocketConnector sslConnector = new SslSocketConnector();
		   sslConnector.setPort(8480);
		   sslConnector.setKeystore("./embeddedJetty/keystore.key");
		   sslConnector.setKeyPassword("Your Password");
		   server.addConnector(sslConnector);
		   
		   WebAppContext wac = new WebAppContext();
		   wac.setContextPath("/");
		   wac.setWar("./embeddedJetty/WebRoot");    // this is path to .war OR TO expanded, existing webapp; WILL FIND web.xml and parse it
		   wac.setDefaultsDescriptor("./embeddedJetty/webdefault.xml");
		   server.addHandler(wac);

		   // configure the request log
		   new File("log").mkdir();
		   RequestLogHandler requestLogHandler = new RequestLogHandler();
		   NCSARequestLog reqLog = new NCSARequestLog("./log/yyyy_mm_dd.request.log");
		   reqLog.setRetainDays(10);
		   reqLog.setAppend(true);
		   reqLog.setExtended(false);
		   reqLog.setLogTimeZone("Canada/Pacific");
		   requestLogHandler.setRequestLog(reqLog);
		   server.addHandler(requestLogHandler);	   

		   server.start();
	}
}
